﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SportsStore.Domain.Abstract;
using SportsStore.Domain.Entities;

namespace SportsStore.WebUI.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        private IProductRepository repository;

        public HomeController(IProductRepository productRepository)
        {
            repository = productRepository;
        }

        public ViewResult Index()
        {
            //IEnumerable<string> categories = repository.Products.Select(p => p.Category).Distinct().ToList();
            //IList<Product> productsToShow = null;
            //foreach (var cat in categories)
            //{
             //   Product pro = repository.Products.SingleOrDefault(p => p.Category == cat);
             //  productsToShow.Add(pro);
            //}
            var productsToShow = repository.Products.GroupBy(p => p.Category).Select(k=>k.FirstOrDefault()); 
            return View(productsToShow);
        }

    }
}
